#include "RecogDoc.h"

void RecogDoc::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BaseDocument::fromJson(json, errorList);

    QJsonArray jsonItems;

    jsonItems = json.value("data").toArray();
    m_data->clear();
    for (int i = 0; i < jsonItems.size(); ++i) {
        shared_ptr<RecogDoc> item = make_shared<RecogDoc>();
        item->fromJson(jsonItems[i].toObject(), errorList);
        m_data->push_back(item);
    }
}

QJsonObject RecogDoc::toJson() const
{
    QJsonObject json = BaseDocument::toJson();

    QJsonArray items;
    items = QJsonArray();

    int index = 0;
    for (auto it = m_data->begin(); it != m_data->end(); ++it, ++index) {
        items.append((*it)->toJson());
    }

    json.insert("data", items);

    return json;
}
